﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FSM.DotNetSSH;

namespace KitTest.Kit
{
   public class SSHKit
    {
        public static void openSSH() {
            try
            {
                KitTest.sshUtil.Util.SshConnectionInfo input = KitTest.sshUtil.Util.GetInput();
                SshShell shell = new SshShell(input.Host, input.User);
                if (input.Pass != null) shell.Password = input.Pass;
                if (input.IdentityFile != null) shell.AddIdentityFile(input.IdentityFile);

                //This statement must be prior to connecting
                shell.RedirectToConsole();

                Console.Write("Connecting...");
                shell.Connect();
                Console.WriteLine("OK");

                while (shell.ShellOpened)
                {
                    System.Threading.Thread.Sleep(500);
                }
                Console.Write("Disconnecting...");
                shell.Close();
                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
